package com.app.service.impl;

import com.app.entity.Banner;
import com.app.mapper.BannerMapper;
import com.app.service.BannerService;
import com.app.service.QiniuService;
import com.app.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jt
 * @since 2021-04-07
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {
    @Autowired
    private QiniuService qiniuService;
    @Autowired
    private BannerMapper carmapMapper;


    @Override
    public void upload(MultipartFile file, Integer weight) {
        try {
            String url = qiniuService.uploadFile(file);
            Banner carmap = new Banner();
            carmap.setUrl(url);
            carmap.setWeight(weight);
            carmapMapper.insert(carmap);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public List<Banner> getCarMap() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByAsc("weight");
        return carmapMapper.selectList(null);
    }

    @Override
    public void updateCarMapWeight(Banner carmap) {
        carmapMapper.updateById(carmap);
    }

    @Override
    public void deleteCarMap(Integer id) {
        carmapMapper.deleteById(id);
    }
}
